package com.voxel.sense.infomsg.module.trace.staff;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.com.common.app.BViewActivity;
import com.example.com.common.utils.NetworkUtils;
import com.example.com.common.utils.ToastUtil;
import com.example.com.common.view.EmptyView;
import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.module.trace.map.CheckinsRecordActivity;
import com.voxel.sense.infomsg.view.decoration.ItemDivider;
import com.voxel.sense.infomsg.view.decoration.LinearItemDecoration;
import com.voxel.sense.infomsg.view.titlebar.TextTitleBar;

import butterknife.BindView;
import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.model.api.response.ClockInUserListEntity;

public class StaffClockInListActivity extends BViewActivity<StaffClockInListContract.Presenter>
        implements StaffClockInListContract.View {
    @BindView(R.id.titlebar)
    TextTitleBar titlebar;
    @BindView(R.id.recycle_view)
    RecyclerView recycle_view;
    @BindView(R.id.empty_view)
    EmptyView empty_view;

    RecyclerAdapter<ClockInUserListEntity.BodyBean> mAdapter;


    public static void show(Context context) {
        Intent intent = new Intent(context, StaffClockInListActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_staff_clock_in_list;
    }


    @Override
    protected StaffClockInListContract.Presenter initPresenter() {
        return new StaffClockInListPresenter(this);
    }

    @Override
    protected void initData() {
        super.initData();
        titlebar.setTitleText("人员列表");
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        recycle_view.setLayoutManager(layoutManager);
        recycle_view.addItemDecoration(new LinearItemDecoration(R.drawable.recycle_divider));
        mAdapter = new StaffListAdapter();
        mPresenter.doLoadData();
        recycle_view.setAdapter(mAdapter);
        empty_view.bind(recycle_view);
        empty_view.addRefreshBtnEvent(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!NetworkUtils.isConnected()) {
                    ToastUtil.showToastLong(Factory.app(), getString(R.string.network_unavailable));
                    return;
                }
                showLoading("");
                empty_view.triggerOk();
                mPresenter.doLoadData();
            }
        });
    }

    @Override
    protected void initEven() {
        super.initEven();
        mAdapter.setListener(new RecyclerAdapter.AdapterListenerImpl<ClockInUserListEntity.BodyBean>() {
            @Override
            public void onItemClick(RecyclerAdapter.ViewHolder holder, ClockInUserListEntity.BodyBean bean) {
                super.onItemClick(holder, bean);
                CheckinsRecordActivity.show(StaffClockInListActivity.this, bean.getUserId(), bean.getUserName());
            }
        });
    }

    @Override
    public RecyclerAdapter<ClockInUserListEntity.BodyBean> getRecyclerViewAdapter() {
        return mAdapter;
    }

    @Override
    public void onAdapterDataChanged() {

    }

    @Override
    public void showEmptyView(String desc, boolean btnVisible) {
        boolean b = mAdapter.getItemCount() > 0 ? true : false;
        if (!b) {
            empty_view.triggerError(desc);
        }
    }

    @Override
    public void onShowNoMore(boolean b) {

    }

    @Override
    public void onRefreshFinish() {
        empty_view.triggerOkOrEmpty(mAdapter.getItemCount() > 0 ? true : false);
    }

    @Override
    public void onLoadMoreFinish() {

    }

}
